package com.StarStudio.Service.Impl;

import com.StarStudio.Mapper.ZoneMapper;
import com.StarStudio.Service.DeviceService;
import com.StarStudio.Domain.Device;
import com.StarStudio.Mapper.DeviceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeviceServiceImpl implements DeviceService {

    @Autowired
    private DeviceMapper deviceMapper;

    @Autowired
    private ZoneMapper zoneMapper;

    @Override
    public List<Device> getAll() {
        return deviceMapper.getAll();
    }

    @Override
    public Device getById(int deviceId) {
        return deviceMapper.getById(deviceId);
    }

    @Override
    public void add(Device device, int zoneId) {
        String zoneNameByZoneId = zoneMapper.getZoneNameByZoneId(zoneId);
        device.setDevice_location(zoneNameByZoneId);
        deviceMapper.add(device);
        deviceMapper.addToZone_Device(zoneId, device.getDevice_id());
    }

    @Override
    public void update(Device device) {
        deviceMapper.update(device);
    }

    @Override
    public void delete(int deviceId) {
        deviceMapper.delete(deviceId);
    }
}